package com.tgy.algorithm._经典题目01;

public class _025_子数组的最大累加和 {


    public static int subArrMaxSum(int[] nums) {

        if (nums == null || nums.length == 0) {
            return 0;
        }

        int sum = 0;
        int ret = Integer.MIN_VALUE;
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            sum += nums[i];
            ret = Math.max(sum,ret);
            // 丢弃之前的数组和
            if (sum < 0) {
                sum = 0;
            }
        }

        return ret;
    }

    public static void main(String[] args) {
        int[] nums = {3,-2,2,3};
        int val = subArrMaxSum(nums);
        System.out.println(val);
    }
}
